/**
 * 
 */
package com.alianzamedica.controllers.prescription;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.objectsearch.sqlsearch.ObjectSearch;
import org.w3c.dom.Document;

import com.alianzamedica.businessobject.Prescription;
import com.alianzamedica.tools.Enviroment;

/**
 * @author RMarquez_Inf
 * 
 */
public class DeletePrescriptionAction extends Action {
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.
	 * ActionMapping, org.apache.struts.action.ActionForm,
	 * javax.servlet.ServletRequest, javax.servlet.ServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Enviroment env = Enviroment.getInstance();
		Document doc = env.getDocument();
		ObjectSearch search = new ObjectSearch(doc,
				"com.alianzamedica.connection.ConnectionImpl");
		String id = request.getParameter("id");
		int idN=Integer.parseInt(id);
		if (id != null) {
			Prescription l = new Prescription();
			l.setId(idN);
			search.deleteObject(l);
		}

		String mensaje = "Se ha borrado la receta de manera exitosa";
		String linkRetorno = "/admin/prescription/list.do";
		request.setAttribute("mensaje", mensaje);
		request.setAttribute("linkRetorno", linkRetorno);
		return mapping.findForward("success");
	}
}
